<template>
  <div class="component-wrapper" :style="wrapper_style" @click="toUrl">
    <div v-if="datas.show_title" :style="title_style" class="title">{{ title }}</div>
    <div v-if="datas.show_second_title" :style="second_title_style" class="second-title">{{ second_title }}</div>
  </div>
</template>

<script>
export default {
  props: ['id', 'datas'],
  data() {
    return {
    };
  },
  created() {},
  activated() {},
  computed: {
    /** 样式 */
    wrapper_style() {
      const {
        preview_color,
        padding_top,
        padding_bottom,
        padding_left,
        padding_right,
      } = this.datas;

      return `
                width: 100%;
                padding-top: ${padding_top}px;
                padding-bottom: ${padding_bottom}px;
                padding-left: ${padding_left}px;
                padding-right: ${padding_right}px;
                background-color: ${preview_color.color};
                background-image: url(${preview_color.isColor == 2? preview_color.image: ''});
                background-size: 100% auto;
                bakcground-position: center;
            `;
    },

    /** 标题样式 */
    title_style() {
      const {
        text_style,
        text_align,
        text_size,
        text_color
      } = this.datas;
      return `
                font-weight: ${text_style.includes('1')?'bold':''};
                font-style: ${text_style.includes('2')?'italic':''};
                text-align: ${text_align};
                font-size: ${text_size}px;
                color: ${text_color};
            `;
    },

    /** 副标题样式 */
    second_title_style() {
      const {
        second_text_style,
        second_text_align,
        second_text_size,
        second_text_color
      } = this.datas;
      return `
                font-weight: ${second_text_style.includes('1')?'bold':''};
                font-style: ${second_text_style.includes('2')?'italic':''};
                text-align: ${second_text_align};
                font-size: ${second_text_size}px;
                color: ${second_text_color};
            `;
    },

    /** 标题 */
    title() {
      return this.datas.title || '标题';
    },
    second_title() {
      return this.datas.second_title || '副标题';
    },

  },
  methods: {
    toUrl() {
      let item = this.datas.link;
      if(item.is_h5 == 2 && this.fun.isApp()) {
        YDB.MiniWX(item.gh_id, item.minApp_link);
        return;
      }
      if(item.is_h5 == 2 &&  this.fun.isCPS()) {
        let json = {
          mini_route: item.minApp_link,
          mini_id: item.gh_id,
        };
        if (this.fun.isIosOrAndroid() === "ios") {
          miniWXIOS({ body: "miniWXIOS", json: JSON.stringify(json) });
        } else {
          miniWXAndroid(JSON.stringify(json));
        }
        return;
      }

      if(item.is_h5 == 7) {
        if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
          let json = { name: 'task' };
          if (this.fun.isIosOrAndroid() === "ios") {
            toUrlIOS({ body: "toUrlIOS", json: JSON.stringify(json) });
          } else {
            toUrlAndroid(JSON.stringify(json));
          }
        }else if(item.link) {
          window.location.href = item.link;
        }
      }else if (item.is_h5 == 1 && item.link) {
        window.location.href = item.link;
      }
    },
  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  .component-wrapper {
    display: block;
    max-width: 100%;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
    text-decoration: none;
  }
</style>
